import request from '@/utils/request.ts'
import type { PagesData, ResponseData } from '@/api/type.ts'
import type { Role } from '@/api/acl/role/type.ts'

enum API {
  ROLE_LIST_URL = '/admin/acl/role',
  ROLE_INFO_URL = '/admin/acl/role/get',
  ROLE_ADD_URL = '/admin/acl/role/save',
  ROLE_UPDATE_URL = '/admin/acl/role/update',
  ROLE_DELETE_URL = '/admin/acl/role/remove',
}

export const reqRoleList = (page: number, limit: number, roleName: string) => {
  return request.get<any, ResponseData<PagesData<Role>>>(
    `${API.ROLE_LIST_URL}/${page}/${limit}?roleName=${roleName}`,
  )
}

export const reqRoleInfo = (roleId: number) => {
  return request.get<any, ResponseData<Role>>(`${API.ROLE_INFO_URL}/${roleId}`)
}

export const reqRoleAddOrUpdate = (role: Role) => {
  if (role?.id) {
    return request.put<any, ResponseData<any>>(API.ROLE_UPDATE_URL, role)
  } else {
    return request.post<any, ResponseData<any>>(API.ROLE_ADD_URL, role)
  }
}

export const reqRoleDelete = (roleId: number) => {
  return request.delete<any, ResponseData<any>>(
    API.ROLE_DELETE_URL + '/' + roleId,
  )
}
